package com.ytc.media.config;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/*
* 抽取工具类
* */
@Component
public class VodTemplate {
    @Autowired
    private DefaultAcsClient client;
    /**
     //     * 获取凭证:CreateUploadVideoResponse
     //     * 返回：视频id
     //     * @throws Exception
     //     */
   public CreateUploadVideoResponse createUploadVideo(String title,String filename) throws Exception {
       CreateUploadVideoRequest request = new CreateUploadVideoRequest();
       request.setTitle(title); //标题
       request.setFileName(filename);  //文件名称
       CreateUploadVideoResponse response = client.getAcsResponse(request);
       return response;
   }
   /**
    * 刷新凭证(针对某个上传的视频，刷新)
    *   上传凭证具有有效期，在规定时间内如果没有上传完成，阿里云拒绝接受。
    *   更新凭证，使用新的凭证继续上传
    *   返回值：RefreshUploadVideoResponse
    */
   public RefreshUploadVideoResponse refreshUploadVideo(String videoId) throws Exception {
       RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
       //音频或视频ID
       request.setVideoId(videoId);
       RefreshUploadVideoResponse response = client.getAcsResponse(request);
       return response;
   }

   /**
    * 获取播放地址
    *  响应对象GetPlayInfoRequest
    *    GetPlayInfoResponse --> playinfoList --> 获取第一个元素 --> playUrl(播放地址)，duration(播放时长)
    */
   public GetPlayInfoResponse getPlayInfo(String videoId) throws Exception {
       GetPlayInfoRequest request = new GetPlayInfoRequest();
       request.setVideoId(videoId);
       GetPlayInfoResponse response = client.getAcsResponse(request);
       return response;
   }
}
